package com.clickpaas.governmentcloud.service.exactmatchingservice.impl;

import com.bizcloud.ipaas.tb4093760b8224c4fbcff37d3fa266753.d20210207141638.codegen.*;
import com.bizcloud.ipaas.tb4093760b8224c4fbcff37d3fa266753.d20210207141638.model.*;
import com.clickpaas.governmentcloud.common.ServerResponse;
import com.clickpaas.governmentcloud.entity.policyEntity.PolicyEntity;
import com.clickpaas.governmentcloud.service.exactmatchingservice.ExactMatchingService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ExactMatchingServiceImpl implements ExactMatchingService {

	@Override
	public ServerResponse<?> insertPolicy(PolicyEntity policy) {
		try {
			// 企业名称
			String enterpriseName = policy.getEnterpriseName();
			// 企业所属区域
			String enterpriseArea = policy.getEnterpriseArea();
			// 注册资本
			Integer registeredCapital = policy.getRegisteredCapital();
			// 注册时间
			String registeredTime = policy.getRegisteredTime();
			// 所属行业
	    	List<String> industrys = policy.getIndustrys();
	    	// 主要产品或服务
	    	String mainProductsOrServices = policy.getMainProductsOrServices();
	    	// 所属园区
	    	String park = policy.getPark();
	    	// 企业规模
	    	String enterpriseScale = policy.getEnterpriseScale();
	    	// 独立法人
	    	String independentLegalPerson = policy.getIndependentLegalPerson();
	    	// 是否违法
	    	String dishonesty = policy.getDishonesty();
	    	// 参与标准制定
	    	Integer participateDevelopment = policy.getParticipateDevelopment();
	    	// 专业化 是否在行业细分市场领域内国内排名前10
    		String industryTop10 = policy.getIndustryTop10();
    		// 市占率
    		String marketShare = policy.getMarketShare();
    		// 特：品牌具有一定特色，获得过驰名商标、著名商标、名牌产品等荣誉称号（项）
    		Integer brandCharacteristics = policy.getBrandCharacteristics();
    		// 新：提供产品或服务满足“四新”经济发展特征，具有一定创新性，估值 （亿美元）1
    		String productOrService = policy.getProductOrService();
    		// 新：提供产品或服务满足“四新”经济发展特征，具有一定创新性，估值 （亿美元）2 数字
    		BigDecimal productOrService2 = policy.getProductOrService2();
	    	// 企业资质
    		List<String> enterpriseQualification = policy.getEnterpriseQualification();
    		String enterpriseQualificationStr = "";
    		if(enterpriseQualification != null && enterpriseQualification.size() > 0) {
    			enterpriseQualificationStr = enterpriseQualificationStr.replaceAll("\\[", "").replaceAll("\\]", "");
    		}
    		// 职工总数
	    	Integer empTotal = policy.getEmpTotal();
	    	// 研发人员数
	    	Integer rOrDpersonnel = policy.getDpersonnel();
	    	// 大前年研发费用
	    	Integer rOrDexpensesInTheYearBefore = policy.getDexpensesInTheYearBefore();
	    	// 前年研发费用
	    	Integer rOrDExpensesOfThePreviousYear = policy.getDexpensesOfThePreviousYear();
			// 去年研发费用
	    	Integer rOrDExpensesLastYear = policy.getDexpensesLastYear();
	    	// 大前年营业收入
	    	Integer yearBeforeTheUniversity = policy.getYearBeforeTheUniversity();
	    	// 前年营业收入
	    	Integer businessIncomeOfThePpreviousYear = policy.getBusinessIncomeOfThePpreviousYear();
	    	// 去年度营业收入
	    	Integer businessIncomeOfLastYear = policy.getBusinessIncomeOfLastYear();
	    	// 发明专利数
	    	Integer inventionPatentsNumberOneClass = policy.getInventionPatentsNumberOneClass();
	    	// 集成电路数
	    	Integer integratedCircuitsOneClass = policy.getIntegratedCircuitsOneClass();
	    	// 实用新型专利数
	    	Integer utilityModelPatentsTwoClass = policy.getUtilityModelPatentsTwoClass();
	    	// 外观专利数
	    	Integer appearancePatentsTwoClass = policy.getAppearancePatentsTwoClass();
	    	// 软件著作权数
	    	Integer softwareCopyrightTwoClass = policy.getSoftwareCopyrightTwoClass();
	    	// 上年度高新产品
	    	Integer highTechProductsOfLastYear = policy.getHighTechProductsOfLastYear();
	    	// 科技成果转化
	    	Integer technologicalAchievements = policy.getTechnologicalAchievements();
	    	// 研发组织管理 是否建立制定并完善《企业研发的组织管理制度》等研发管理制度体系（知识产权保护、人才引进培养、创新激励）
    		String formulateAndImproved = policy.getFormulatedAndImproved();
    		// 产学研 是否同1所以上大学或科研院校签订产学研合作协议。
    		String researchInstitution = policy.getResearchInstitution();
    		// 设备研发
    		String researchAndDevelopmentSite = policy.getResearchAndDevelopmentSite();
    		// 是否有良好的经营管理团队，有较强的风险控制机制和健全的规章制度
    		String rulesAndRegulations = policy.getRulesAndRegulations();
    		// 是否有在建项目
    		String projectsUnderConstruction = policy.getProjectsUnderConstruction();
    		// 项目内容
    		String projectContent = policy.getProjectContent();
    		// 年服务中小企业
    		Integer annualNumberOfSMEs = policy.getAnnualNumberOfSMEs();
    		// 资产总额
    		Integer totalAssets = policy.getTotalAssets();
    		// 净资产（万元）
    		Integer netAssets = policy.getNetAssets();
    		// 净资产增长率
			Integer growthRateOfNetAssets = 0;
			if (null != policy.getGrowthRateOfNetAssets()){
				growthRateOfNetAssets = policy.getGrowthRateOfNetAssets();
			}

    		// 负债总额（万元）
    		Integer totalLiabilities = policy.getTotalLiabilities();
    		// 大前年净利润（万元）
    		Integer annualNetProfitOfThePreviousYear = policy.getAnnualNetProfitOfThePreviousYear();
    		// 前年净利润（万元）
    		Integer netProfitOfThePreviousYear = policy.getNetProfitOfThePreviousYear();
    		// 去年度净利润（万元）
    		Integer netProfitOfLastYear = policy.getNetProfitOfLastYear();
    		// 上一年度税收总额（万元）
    		Integer totalTaxRevenueOfLastYear = policy.getTotalTaxRevenueOfLastYear();
    		// 去年节约能耗(KWh）
    		Integer energySavingLastYear = policy.getEnergySavingLastYear();
    		// 是否留学人员
    		String overseasStudentsOrNot = policy.getOverseasStudentsOrNot();
    		// 年龄
    		Integer age = policy.getAge();
    		// 户籍
    		String householdRegister = policy.getHouseholdRegister();
    		// 主持或参与项目/课题情况
    		String hostingOrParticipatingInProjects = policy.getHostingOrParticipatingInProjects();
    		// 公司名称
    		String corpName = policy.getCorpName();
    		
    		TaccuratematchingApi taccuratematchingApi = new TaccuratematchingApi();
			TAccurateMatchingDTOQuery tAccurateMatchingQuery = new TAccurateMatchingDTOQuery();
    		tAccurateMatchingQuery.setUserInfo(corpName);
			TAccurateMatchingDTOUpdate tAccurateMatchingUpdate = new TAccurateMatchingDTOUpdate();
    		tAccurateMatchingUpdate.setName(enterpriseName);
    		tAccurateMatchingUpdate.setArea(enterpriseArea);
    		if(registeredCapital != null) {
    			tAccurateMatchingUpdate.setRegisteredCapital(new BigDecimal(registeredCapital));
    		}
    		tAccurateMatchingUpdate.setSigndate(registeredTime);
//    		tAccurateMatchingUpdate.setIndustry(industrys);
    		tAccurateMatchingUpdate.setProductorservice(mainProductsOrServices);
    		tAccurateMatchingUpdate.setPark(park);
    		tAccurateMatchingUpdate.setScale(enterpriseScale);
    		tAccurateMatchingUpdate.setIndividual(independentLegalPerson);
    		tAccurateMatchingUpdate.setWhetherviolate(dishonesty);
    		tAccurateMatchingUpdate.setStandardSettingAmount(participateDevelopment);
    		tAccurateMatchingUpdate.setMarketRanking(industryTop10);
    		tAccurateMatchingUpdate.setMarketoccupancy(marketShare);
    		tAccurateMatchingUpdate.setHonor(brandCharacteristics);
    		tAccurateMatchingUpdate.setDescribe(productOrService);
    		tAccurateMatchingUpdate.setEstimatevalue(productOrService2);
    		tAccurateMatchingUpdate.setQuality(enterpriseQualificationStr);
    		tAccurateMatchingUpdate.setWorkernumber(empTotal);
    		tAccurateMatchingUpdate.setRdnumber(rOrDpersonnel);
    		if(rOrDexpensesInTheYearBefore != null) {
    			tAccurateMatchingUpdate.setRdExpensesSpentThreeYearsAgo(new BigDecimal(rOrDexpensesInTheYearBefore));
    		}
    		if(rOrDExpensesOfThePreviousYear != null) {
    			tAccurateMatchingUpdate.setRdExpensesSpentTwoYearsAgo(new BigDecimal(rOrDExpensesOfThePreviousYear));
    		}
    		if(rOrDExpensesLastYear != null) {
    			tAccurateMatchingUpdate.setRdExpensesSpentLastYear(new BigDecimal(rOrDExpensesLastYear));
    		}
    		
    		tAccurateMatchingUpdate.setTyaincome(yearBeforeTheUniversity);
    		tAccurateMatchingUpdate.setYblastyearincome(businessIncomeOfThePpreviousYear);
    		tAccurateMatchingUpdate.setLastyearincome(businessIncomeOfLastYear);
    		tAccurateMatchingUpdate.setInvent(inventionPatentsNumberOneClass);
    		tAccurateMatchingUpdate.setElectric(integratedCircuitsOneClass);
    		tAccurateMatchingUpdate.setPracticalnew(utilityModelPatentsTwoClass);
    		tAccurateMatchingUpdate.setAppearance(appearancePatentsTwoClass);
    		tAccurateMatchingUpdate.setSoftware(softwareCopyrightTwoClass);
    		tAccurateMatchingUpdate.setHightechincome(highTechProductsOfLastYear);
    		tAccurateMatchingUpdate.setTechtransfer(technologicalAchievements);
    		tAccurateMatchingUpdate.setWanshantixi(formulateAndImproved);
    		tAccurateMatchingUpdate.setXueyanhezuo(researchInstitution);
    		tAccurateMatchingUpdate.setChangdishebei(researchAndDevelopmentSite);
    		tAccurateMatchingUpdate.setTuanduifengkong(rulesAndRegulations);
    		tAccurateMatchingUpdate.setUnderconstruction(projectsUnderConstruction);
    		tAccurateMatchingUpdate.setContent(projectContent);
    		tAccurateMatchingUpdate.setServe(annualNumberOfSMEs);
    		tAccurateMatchingUpdate.setAsset(totalAssets);
    		tAccurateMatchingUpdate.setNetasset(netAssets);
    		tAccurateMatchingUpdate.setNetassetrise(new BigDecimal(growthRateOfNetAssets));
    		tAccurateMatchingUpdate.setLiability(totalLiabilities);
    		tAccurateMatchingUpdate.setTyaprofit(annualNetProfitOfThePreviousYear);
    		tAccurateMatchingUpdate.setYblyprofit(netProfitOfThePreviousYear);
    		tAccurateMatchingUpdate.setLyprofit(netProfitOfLastYear);
    		tAccurateMatchingUpdate.setLytax(totalTaxRevenueOfLastYear);
    		tAccurateMatchingUpdate.setLysaveenergy(energySavingLastYear);
    		tAccurateMatchingUpdate.setGoabroad(String.valueOf(overseasStudentsOrNot));
    		tAccurateMatchingUpdate.setAge(age);
    		tAccurateMatchingUpdate.setCensus(householdRegister);
    		tAccurateMatchingUpdate.setProjects(hostingOrParticipatingInProjects);
    		tAccurateMatchingUpdate.setUserInfo(corpName);
    		
    		SaveOrUpdatetAccurateMatchingDTO saveOrUpdatetAccurateMatchingDTO1 = new SaveOrUpdatetAccurateMatchingDTO();
    		saveOrUpdatetAccurateMatchingDTO1.setQuery(tAccurateMatchingQuery);
			//tAccurateMatchingUpdate.setatsandboxDBId(ConstantExt._SAND_BOX_ID);
    		saveOrUpdatetAccurateMatchingDTO1.setUpdate(tAccurateMatchingUpdate);
    		taccuratematchingApi.saveOrUpdatetAccurateMatchingUsingPOST(saveOrUpdatetAccurateMatchingDTO1).getMessage();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
